import QtQuick 2.11
import QtQuick.Window 2.3
//import QtQuick.Controls 1.4
import QtQuick.Controls 2.2
import QtQuick.Dialogs 1.2
import QtGraphicalEffects 1.0

import ".."
import "../_Global"
import "../_Global/Button"

import "../_Global/Global.js" as GlobalJS
import "../GameJS.js" as GameJS

Item {
    signal s_myDocument()
    signal s_studing()  //学习
    signal s_Group()   //竞技
    signal s_ranking()    //
    signal s_market()   //超市
    signal s_showGameUserInfo() //个人中心
    signal showConfig()

    id: root
    anchors.fill: parent

    Rectangle {
        id: background
        anchors.fill: parent

        Image { //背景
            id: backImage
            source: Global.resource.images.gameCenter.back
            anchors.fill: parent
        }

        ImageButton2 {  //设置
            x: Global.dpW(1820)
            y: Global.dpH(0)
            width: Global.dpW(100)
            height: Global.dpH(100)
            soundEffectClick: Global.resource.effects.effectButton
            bEffectOn: Global.config.bEffectOn
            source: Global._FixResourcePath_R("Media/Images/Exit/Config.png")
            onButtonClicked: {
                showConfig();
            }
        }


        Image { //头像
            id: imageAvatar
            source: (UserInfo.sex == 1) ? Global._FixResourcePath_R("Media/Images/Center/Boy.png")
                                        : Global._FixResourcePath_R("Media/Images/Center/Girl.png")

            x: Global.gamePos.mapGameSchool.rectAvatar.x
            y: Global.gamePos.mapGameSchool.rectAvatar.y
            width: Global.gamePos.mapGameSchool.rectAvatar.width
            height: Global.gamePos.mapGameSchool.rectAvatar.height

            Text {
                id: textName
                text: UserInfo.nickName
                x: Global.gamePos.mapGameSchool.rectAvatarName.x
                y: Global.gamePos.mapGameSchool.rectAvatarName.y
                width: Global.gamePos.mapGameSchool.rectAvatarName.width
                height: Global.gamePos.mapGameSchool.rectAvatarName.height
                horizontalAlignment: Text.AlignHCenter
                verticalAlignment: Text.AlignVCenter
                color: "white"
                font {
                    bold: true
                    pixelSize: Global.gamePos.mapGameSchool.nAvatarNameFontSize
                    //family: ""
                }
                elide: Text.ElideRight
                /*自适应
                onTextChanged: {
                    font.letterSpacing = 0
                    if(textName.contentWidth > textName.width) {
                        font.letterSpacing -= ((textName.contentWidth - textName.width) / textName.text.length)

                    }

                }*/
            }

            Text {
                id: textCore
                text: UserInfo.scoreCount
                x: Global.gamePos.mapGameSchool.rectAvatarScore.x
                y: Global.gamePos.mapGameSchool.rectAvatarScore.y
                width: Global.gamePos.mapGameSchool.rectAvatarScore.width
                height: Global.gamePos.mapGameSchool.rectAvatarScore.height
                horizontalAlignment: Text.AlignHCenter
                verticalAlignment: Text.AlignVCenter
                color: "white"
                font {
                    bold: true
                    pixelSize: Global.gamePos.mapGameSchool.nAvatarScoreFontSize
                    //family: ""
                }
                elide: Text.ElideRight

            }

            MouseArea {
                id: mouseAvatar
                anchors.fill: parent
                onClicked: {
                    //console.debug(123321)
                    s_showGameUserInfo()
                }

                hoverEnabled: true
                onEntered: {
                    _private.showColorOverlay(imageAvatar);
                    cursorShape = Qt.PointingHandCursor;
                }
                onExited: {
                    _private.hideColorOverlay();
                    cursorShape = Qt.ArrowCursor;
                }
            }
        }
        Image { //等级图标
            id: imageLevel
            source: Global._FixResourcePath_R(qsTr("Media/Images/Levels/%1.png").arg(Global.userInfo.userLevel))

            x: Global.gamePos.mapGameSchool.rectUserLevel.x
            y: Global.gamePos.mapGameSchool.rectUserLevel.y
            width: Global.gamePos.mapGameSchool.rectUserLevel.width
            height: Global.gamePos.mapGameSchool.rectUserLevel.height
        }
/*
        //档案
        Rectangle {
            id: rectangle
            x: 48
            y: 40
            width: 91
            height: 120
            gradient: Gradient {
                GradientStop {
                    position: 0
                    color: "#ffffff"
                }

                GradientStop {
                    position: 1
                    color: "#000000"
                }
            }

            Text {
                id: text1
                x: 22
                y: 54
                text: qsTr("我的档案")
                font.pixelSize: 12
            }

            MouseArea {
                id: mouseArea
                anchors.fill: parent
                onClicked: s_myDocument()
            }
        }
*/
        //各模块
        Rectangle {
            id: moduleStudy
            x: Global.gamePos.mapGameSchool.rectStudy.x
            y: Global.gamePos.mapGameSchool.rectStudy.y
            width: Global.gamePos.mapGameSchool.rectStudy.width
            height: Global.gamePos.mapGameSchool.rectStudy.height
            color: "#00000000"

            Image {
                id: imageStudy
                source: Global._FixResourcePath_R("Media/Images/Center/Study.png")
                anchors.fill: parent
            }

            MouseArea {
                id: mouseStudy
                anchors.fill: parent
                onClicked: s_studing()

                hoverEnabled: true
                onEntered: {
                    _private.showColorOverlay(moduleStudy);
                    cursorShape = Qt.PointingHandCursor;
                }
                onExited: {
                    _private.hideColorOverlay();
                    cursorShape = Qt.ArrowCursor;
                }
            }
        }

        ImageButton2 {  //竞技场
            id: moduleSports
            x: Global.gamePos.mapGameSchool.rectSports.x
            y: Global.gamePos.mapGameSchool.rectSports.y
            width: Global.gamePos.mapGameSchool.rectSports.width
            height: Global.gamePos.mapGameSchool.rectSports.height
            //enabled: GameManager.platform == "release" ? false : true
            source: Global._FixResourcePath_R("Media/Images/Center/Sports.png")
            onButtonClicked: {
                if(GameManager.platform == "release")
                    dialogMsg.visible = true;
                else
                    s_Group();
            }
        }

        MessageDialog {
            id: dialogMsg
            text: "敬请期待..."
            title: "消息"
            visible: false
        }

        Rectangle {
            id: moduleRanking
            x: Global.gamePos.mapGameSchool.rectRanking.x
            y: Global.gamePos.mapGameSchool.rectRanking.y
            width: Global.gamePos.mapGameSchool.rectRanking.width
            height: Global.gamePos.mapGameSchool.rectRanking.height
            color: "#00000000"

            Image {
                id: imageRanking
                source: Global._FixResourcePath_R("Media/Images/Center/Ranking.png")
                anchors.fill: parent
            }

            MouseArea {
                id: mouseAreaRanking
                anchors.fill: parent
                onClicked: s_ranking()

                hoverEnabled: true
                onEntered: {
                    _private.showColorOverlay(moduleRanking);
                    cursorShape = Qt.PointingHandCursor;
                }
                onExited: {
                    _private.hideColorOverlay();
                    cursorShape = Qt.ArrowCursor;
                }
            }
        }
/*
        Rectangle {
            id: rectangle4
            x: 329
            y: 131
            width: 91
            height: 120
            gradient: Gradient {
                GradientStop {
                    position: 0
                    color: "#ffffff"
                }

                GradientStop {
                    position: 1
                    color: "#000000"
                }
            }
            Text {
                id: text5
                x: 22
                y: 54
                text: qsTr("校内小卖部")
                font.pixelSize: 12
            }

            MouseArea {
                id: mouseArea4
                anchors.fill: parent
                onClicked: s_market()
            }
        }*/
    }


    QtObject {
        id: _private

        property ColorOverlay colorOverlay:
        //颜色遮罩(不可用时黑色,source必须和本对象同一层次!!!)
        ColorOverlay {
            //id: colorOverlay
            visible: false
            //anchors.fill: imageStudy;
            //source: imageStudy;
            color: "#40FFFFFF"
            parent: background
        }

        function showColorOverlay(image) {
            colorOverlay.anchors.fill = image
            colorOverlay.source = image
            colorOverlay.visible = true

        }
        function hideColorOverlay() {
            colorOverlay.visible = false
        }
    }

    Component.onCompleted: {
    }

}
